var g_Videogroup = new THREE.Group();

//绘制视频异常点
function drawUnsualVideoPoints() {
    //drawVideo();
    createUnsualVideoPoints();
}
function createUnsualVideoPoints() {
    var pointGeometry = new THREE.SphereBufferGeometry( 2, 12, 12 );
    var materical = new THREE.MeshBasicMaterial({
        color:0xff0000
    });
    var mesh = new THREE.Mesh(pointGeometry,materical);
    mesh.position.x = 100;
    mesh.position.y = 100;
    mesh.position.z = 85;
    var mesh1 = new THREE.Mesh(pointGeometry,materical);
    mesh1.position.x = 150;
    mesh1.position.y = 60;
    mesh1.position.z = 167;
    var mesh3 = new THREE.Mesh(pointGeometry,materical);
    mesh3.position.x = 90;
    mesh3.position.y = 120;
    mesh3.position.z = 167;
    var mesh2 = new THREE.Mesh(pointGeometry,materical);
    mesh2.position.x = 150;
    mesh2.position.y = 70;
    mesh2.position.z = 167;

    g_UnusualVideogroup.add(mesh);
    g_UnusualVideogroup.add(mesh1);
    g_UnusualVideogroup.add(mesh2);
    g_UnusualVideogroup.add(mesh3);

    g_UnusualVideogroup.rotation.x = -0.5*Math.PI;
    g_UnusualVideogroup.rotation.z = -0.5*Math.PI;
    for(var i = 0;i<g_UnusualVideogroup.children.length;i++)
    {
        g_UnusualVideogroup.children[i].visible = false;
    }
    g_scene.add( g_UnusualVideogroup );
}
function drawVideo() {
    for(var i = 1;i<51;i++)
    {
        var rand
        if(i >= 3 && i <= 6 ||
           i >= 21 && i <= 26 ||
           i >= 34 && i <= 38)
        {
            rand = 15;
        }
        else
        {
            rand = 10;
        }
        var vertices = getVideoVertexs(i,rand);
        createVideo(vertices,i);
    }
    for(var i = 0;i<g_Videogroup.children.length;i++)
    {
        g_Videogroup.children[i].visible = false;
    }
}
function createVideo(tempVertices,floor)
{
    var videogroup = new THREE.Group();
    videogroup.name = "video-F"+floor;
    for ( var i = 0; i < tempVertices.length;i+=3 ) {
        var sprite = new THREE.CanvasTexture( generateSprite(0));

        var material = new THREE.SpriteMaterial( {
            map: sprite,
            blending: THREE.AdditiveBlending,
            depthTest:false
        } );

        particle = new THREE.Sprite( material );
        particle.scale.x = particle.scale.y = 8;
        particle.position.set(tempVertices[i+0],tempVertices[i+1],tempVertices[i+2]);
        videogroup.add( particle );
    }
    g_Videogroup.add( videogroup );
    g_Videogroup.rotation.x = -0.5*Math.PI;
    g_Videogroup.rotation.z = -0.5*Math.PI;
    g_scene.add( g_Videogroup );
    
}
function getVideoVertexs(count,rand) {
    var vertices = [];
    var tempZ;
    for(var i = 0;i<scatterZ.length;i++)
    {
        if(getFloorNumFromNameId(scatterZ[i][0]) == count)
        {
            
            tempZ = scatterZ[i][1];
            break;
        }
    }
    
    for ( var i = 0; i < rand; i ++ )
    {
        
        var tempX = Math.random()*150;
        var tempY = Math.random()*150;

        if(count >= 3 && count <= 6)
        {
            if(isInPolygon([tempX,tempY],scatterploygn1))
            {
                vertices.push( tempX, tempY, tempZ );
            }
        }
        else if(count >= 21 && count <= 26)
        {
            if(isInPolygon([tempX,tempY],scatterploygn3))
            {
                vertices.push( tempX, tempY, tempZ );
            }
        }
        else if(count >= 34 && count <= 38)
        {
            if(isInPolygon([tempX,tempY],scatterploygn4))
            {
                vertices.push( tempX, tempY, tempZ );
            }
        }
        else if(count >= 42)
        {
            if(isInPolygon([tempX,tempY],scatterploygn21))
            {
                vertices.push( tempX, tempY, tempZ );
            }
        }
        else
        {
            if(isInPolygon([tempX,tempY],scatterploygn21) || isInPolygon([tempX,tempY],scatterploygn22))
            {
                vertices.push( tempX, tempY, tempZ );
            }
        }
    }
    return vertices;
}